<template>
    <div class="shopcar_container">
        <div class="goods-list">
        <div class="mui-card" v-for="(item,i) in shopcarlist" :key="item.id">
            <div class="mui-card-content">
                <div class="mui-card-content-inner">
                    <!-- 选择框按钮 -->
                    <mt-switch 
                    v-model="$store.getters.getgoodsselect[item.id]"
                    @change="selectedchange(item.id,$store.getters.getgoodsselect[item.id])"></mt-switch>
                    <img :src="item.thumb_path" alt="">
                    <div class="info">
                        <h3>{{item.title}} </h3>
                        <p> 
                            <span class="price">￥{{item.sell_price}}</span>
                            <numberbox :initcount="$store.getters.getgoodsselect[item.id]"  :goodsid="item.id"></numberbox>
                            <a href="#" @click.prevent="remove(item.id,i)">删除</a>
                        </p>
                    </div>
                </div>
            </div>
        </div>
        <div class="mui-card">
            <div class="mui-card-content">
                <div class="mui-card-content-inner jiesuan">
                    <div class="left">
                        <p>总计（不含运费）</p>
                        <p>已勾选商品 <span>{{ $store.getters.getdata.count}}</span> 件，
                        总价：￥ <span>{{ $store.getters.getdata.ammount}}</span> </p>
                    </div>
                    <mt-button type="danger" >去结算</mt-button>
                </div>
            </div>
        </div>
    </div>
    </div>
</template>


<script>
import numberbox from '../subcomponents/shopcarnumberbox.vue'
export default {
    data(){
        return{
            shopcarlist:[]
        };  
    },
    created () {
       this.getshopcarlist();
    },
    methods: {
        getshopcarlist(){
        
            var idall=[];
            this.$store.state.car.forEach(item => idall.push(item.id))
                if(idall.length <= 0){
                    return;
                }
            this.$http.get("api/goods/getshopcarlist/"+idall.join(",")).then(result=>{
                if(result.body.status === 0){
                this.shopcarlist = result.body.message;
                console.log(this.shopcarlist)
                }
            })
        },
        remove(id,i){
            //neicun
            this.shopcarlist.splice(i,1);
            //ben  di
            
            this.$store.commit("removeinfo",id);
        },
        selectedchange(id,val){
            this.$store.commit("updateselected",{id:id,selected:val})
        },
    },
    
    components: {
        numberbox
    }
}
</script>

<style lang="scss" scoped>
.shopcar_container{
    background-color: #ccc;
    overflow: hidden;
    .mui-card-content-inner{
        display: flex;
        align-items: center;

    }
    .jiesuan{
        display: flex;
        justify-content: space-between;
        align-items: center;
         
        span{
            color: red;
            font-weight: bold;
        }
    }
    img{
        width: 60px;
        height: 60px;
    }
    h3{
        font-size: 13px;
    }
    .info{
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .price{
            color: red;
            font-weight: bold;
        }
    }
    	.goods-list{
		img{
			width: 60px;
			height: 60px;
		}
		h1{
			font-size: 13px;
		}
		.info{
			.price{
				color: red;
				font-weight: bold;
			}
		}
	}
}

</style>